from datetime import timedelta

#时间段
a = timedelta(days = 2, hours = 6)
b = timedelta(hours = 4.5)
c = a + b
print(c)
print(c.days)
print('seconds:', c.seconds)
print('hours:', c.seconds / 3600)
print('total_seconds:', c.total_seconds())

from datetime import datetime
a = datetime(2012, 9, 23)
print(a + timedelta(days = 10))
b = datetime(2012, 12, 21)
d = b - a
print(d.days)
now = datetime.today()
print(now)
print(now + timedelta(minutes=10))

#在计算的时候，需要注意的是 datetime 会自动处理闰年
a = datetime(2012, 3, 1)
b = datetime(2012, 2, 28)
print((a - b).days)

c = datetime(2013, 3, 1)
d = datetime(2013, 2,28)
print((c - d).days)
